package com.lovo.project.service.impl;

import com.lovo.project.dao.GoodDAO;
import com.lovo.project.dao.OrderDAO;
import com.lovo.project.enums.GoodCodeEnum;
import com.lovo.project.enums.OrderCodeEnum;
import com.lovo.project.exception.OurException;
import com.lovo.project.model.GoodDO;
import com.lovo.project.model.OrderDO;
import com.lovo.project.service.GoodService;
import com.lovo.project.util.MyBatisUtil;
import lombok.Data;
import org.apache.ibatis.session.SqlSession;

import java.io.Serializable;
import java.util.List;

/**
 * @author pankez
 * @title 商品业务接口实现类
 * @data 2020/11/5 14:10
 */
@Data
public class GoodServiceImpl implements GoodService {
    @Override
    public List<GoodDO> findGoodsByOrderId(Integer id) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        GoodDAO goodDao = sqlSession.getMapper(GoodDAO.class);
        try{
            List<GoodDO> list = goodDao.findGoodsByOrderId(id);
            if (list == null){
                throw new OurException(GoodCodeEnum.GOOD_FINDOUT_ENUM);
            }
            return list;
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            sqlSession.close();
        }
        return null;
    }
}
